package com.controller;

import com.constant.Constant;
import com.entity.GoldPoints;
import com.entity.User;
import com.github.pagehelper.PageInfo;
import com.service.GoldPointsService;
import com.service.UserService;
import com.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@RequestMapping("/gp")
public class GoldPointsController {
    @Autowired
    GoldPointsService goldPointsService;

    @Autowired
    UserService userService;

    //分页显示积分记录
    @RequestMapping("/findRecord.do")
    @ResponseBody
    public AjaxResult findRecord(HttpServletRequest request, HttpSession session) {
        Integer pageNo = Integer.parseInt(request.getParameter("pageNo"));
        User user = (User) session.getAttribute(Constant.SESSION_USER);
        int user_id=user.getId();
        GoldPoints goldPoints=new GoldPoints();
        goldPoints.setUser_id(user_id);
        PageInfo recordByPageNo=goldPointsService.findGoldPointByPageInNo(goldPoints,pageNo);
        System.out.println(recordByPageNo);
        return AjaxResult.isOk("success",recordByPageNo);
    }
}
